/**
 * Created by LeungZ on 2016/10/17.
 */
class Ctrl {
    constructor($scope) {
        "ngInject";
        if (!$scope.service.envs) $scope.service.envs = [];
    }

    envAdd(envs) {
        envs.push({
            key: '',
            value: ''
        });
    }

    envRemove(index, envs) {
        envs.splice(index, 1);
    }

    checkEnvKey(index, envs, form) {
        if (envs[index].key) {
            for (var i in envs) {
                if (envs[i].key == envs[index].key && i != index) {
                    return form['key' + index].$setValidity('duplicate', false);
                }
            }
            form['key' + index].$setValidity('duplicate', true);
        }
    }
}
export default Ctrl